package com.sharding.sphere.config;

import org.apache.shardingsphere.driver.api.yaml.YamlShardingSphereDataSourceFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;

import javax.sql.DataSource;
import java.io.File;


@Configuration
public class DataSourceConfig {
//    @Value("${spring.datasource.url}")
//    private String masterUrl;
//    @Value("${spring.datasource.username}")
//    private String user;
//    @Value("${spring.datasource.password}")
//    private String password;
//    @Value("${spring.datasource.driverClassName}")
//    private String driverName;

    @Bean
    public DataSource dataSource() throws Exception {
        File file = new ClassPathResource("config-sharding.yml").getFile();
        return YamlShardingSphereDataSourceFactory.createDataSource(file);
    }
/*    @Bean
    @Primary
    public DataSource masterDataSource() {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName(driverName);
        dataSource.setUrl(masterUrl);
        dataSource.setUsername(user);
        dataSource.setPassword(password);
        return dataSource;
    }*/
}
